<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for javascripts/SqlLab/components/VisualizeModal.jsx</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../../prettify.css" />
    <link rel="stylesheet" href="../../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../../index.html">All files</a> / <a href="index.html">javascripts/SqlLab/components</a> VisualizeModal.jsx
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">43.75% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>42/96</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">36% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>18/50</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">20% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>3/15</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">45.56% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>41/90</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">6x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">/* global notify */
import React from 'react';
import { Alert, Button, Col, Modal } from 'react-bootstrap';
&nbsp;
import Select from 'react-select';
import { Table } from 'reactable';
import shortid from 'shortid';
import $ from 'jquery';
import { getExploreUrl } from '../../explorev2/exploreUtils';
&nbsp;
const CHART_TYPES = [
  { value: 'dist_bar', label: 'Distribution - Bar Chart', requiresTime: false },
  { value: 'pie', label: 'Pie Chart', requiresTime: false },
  { value: 'line', label: 'Time Series - Line Chart', requiresTime: true },
  { value: 'bar', label: 'Time Series - Bar Chart', requiresTime: true },
];
&nbsp;
const propTypes = {
  onHide: React.PropTypes.func,
  query: React.PropTypes.object,
  show: React.PropTypes.bool,
};
const defaultProps = {
  show: false,
  query: {},
  onHide: <span class="fstat-no" title="function not covered" >() =&gt; </span>{},
};
&nbsp;
class VisualizeModal extends React.PureComponent {
  constructor(props) <span class="branch-1 cbranch-no" title="branch not covered" >{</span>
    super(props);
    this.state = {
      chartType: CHART_TYPES[0],
      datasourceName: this.datasourceName(),
      columns: {},
      hints: [],
    };
  }
  componentDidMount() {
    this.validate();
  }
  componentWillReceiveProps(nextProps) {
<span class="cstat-no" title="statement not covered" >    this.setStateFromProps(nextProps);</span>
  }
  setStateFromProps(props) {
<span class="cstat-no" title="statement not covered" >    if (</span>
        !props.query ||
        !props.query.results ||
        !props.query.results.columns) {
<span class="cstat-no" title="statement not covered" >      return;</span>
    }
    c</span>onst columns = <span class="cstat-no" title="statement not covered" >{};
<span class="cstat-no" title="statement not covered" >    props.query.results.columns.forEach(<span class="fstat-no" title="function not covered" >(</span>col) =&gt; {</span>
<span class="cstat-no" title="statement not covered" >      columns[col.name] = col;</span>
    });
<span class="cstat-no" title="statement not covered" >    this.setState({ columns });</span>
  }
  datasourceName() {
    const { query } = this.props;
    const uniqueId = shortid.generate();
    let datasourceName = uniqueId;
    if (query) {
      d</span>atasourceName = query.user ? `${query.user}-` : <span class="branch-1 cbranch-no" title="branch not covered" >'';
      d</span>atasourceName += query.db ? `${query.db}-` : <span class="branch-1 cbranch-no" title="branch not covered" >'';
      datasourceName += `${query.tab}-${uniqueId}`;
    }
    return datasourceName;
  }
  validate() {
    const hints = [];
    const cols = this.mergedColumns();
    const re = /^\w+$/;
    Object.keys(cols).forEach(<span class="fstat-no" title="function not covered" >(</span>colName) =&gt; {
<span class="cstat-no" title="statement not covered" >      if (!re.test(colName)) {</span>
<span class="cstat-no" title="statement not covered" >        hints.push(</span>
          &lt;div&gt;
            "{colName}" is not right as a column name, please alias it
            (as in SELECT count(*) &lt;strong&gt;AS my_alias&lt;/strong&gt;) using only
            alphanumeric characters and underscores
          &lt;/div&gt;);
      }
    });
    <span class="missing-if-branch" title="if path not taken" >I</span>if (this.state.chartType === null) {
<span class="cstat-no" title="statement not covered" >      hints.push('Pick a chart type!');</span>
    } else <span class="missing-if-branch" title="if path not taken" >I</span>if (this.state.chartType.requiresTime) {
      l</span>et hasTime = <span class="cstat-no" title="statement not covered" >false;
<span class="cstat-no" title="statement not covered" >      for (const colName in cols) {</span>
        c</span>onst col = <span class="cstat-no" title="statement not covered" >cols[colName];
<span class="cstat-no" title="statement not covered" >        if (col.hasOwnProperty('is_date') &amp;&amp; col.is_date) {</span>
<span class="cstat-no" title="statement not covered" >          hasTime = true;</span>
        }
      }
<span class="cstat-no" title="statement not covered" >      if (!hasTime) {</span>
<span class="cstat-no" title="statement not covered" >        hints.push(</span>
          'To use this chart type you need at least one column ' +
          'flagged as a date');
      }
    }
    this.setState({ hints });
  }
  changeChartType(option) {
<span class="cstat-no" title="statement not covered" >    this.setState({ chartType: option }, this.validate);</span>
  }
  mergedColumns() {
    const columns = Object.assign({}, this.state.columns);
    <span class="missing-if-branch" title="if path not taken" >I</span>i</span>f (this.props.query &amp;&amp; <span class="branch-1 cbranch-no" title="branch not covered" >this.props.query.results.columns) {
<span class="cstat-no" title="statement not covered" >      this.props.query.results.columns.forEach(<span class="fstat-no" title="function not covered" >(</span>col) =&gt; {</span>
<span class="cstat-no" title="statement not covered" >        if (columns[col.name] === undefined) {</span>
<span class="cstat-no" title="statement not covered" >          columns[col.name] = col;</span>
        }
      });
    }
    return columns;
  }
  visualize() <span class="cstat-no" title="statement not covered" >{</span>
    c</span>onst vizOptions = <span class="cstat-no" title="statement not covered" >{
      chartType: this.state.chartType.value,
      datasourceName: this.state.datasourceName,
      columns: this.state.columns,
      sql: this.props.query.sql,
      dbId: this.props.query.dbId,
    };
<span class="cstat-no" title="statement not covered" >    notify.info('Creating a data source and popping a new tab');</span>
<span class="cstat-no" title="statement not covered" >    $.ajax({</span>
      type: 'POST',
      url: '/superset/sqllab_viz/',
      async: false,
      data: {
        data: JSON.stringify(vizOptions),
      },
      dataType: 'json',
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      success: <span class="fstat-no" title="function not covered" >resp =&gt; </span>{</span></span>
        c</span>onst columns = <span class="cstat-no" title="statement not covered" >Object.keys(this.state.columns).map(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >k =&gt; this.state.columns[k]);</span></span>
        c</span>onst data = <span class="cstat-no" title="statement not covered" >JSON.parse(resp);
        c</span>onst mainMetric = <span class="cstat-no" title="statement not covered" >columns.filter(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >d =&gt; d.agg)[0];</span></span>
        c</span>onst mainGroupBy = <span class="cstat-no" title="statement not covered" >columns.filter(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >d =&gt; d.is_dim)[0];</span></span>
        c</span>onst formData = <span class="cstat-no" title="statement not covered" >{
          datasource: `${data.table_id}__table`,
          viz_type: this.state.chartType.value,
          since: '100 years ago',
          limit: '0',
        };
<span class="cstat-no" title="statement not covered" >        if (mainMetric) {</span>
<span class="cstat-no" title="statement not covered" >          formData.metrics = [mainMetric.name];</span>
<span class="cstat-no" title="statement not covered" >          formData.metric = mainMetric.name;</span>
        }
<span class="cstat-no" title="statement not covered" >        if (mainGroupBy) {</span>
<span class="cstat-no" title="statement not covered" >          formData.groupby = mainGroupBy.name;</span>
        }
<span class="cstat-no" title="statement not covered" >        window.open(getExploreUrl(formData));</span>
      },
<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >      error: <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >() =&gt; notify('An error occurred while creating the data source'),</span></span></span></span>
    });
  }
  changeDatasourceName(event) {
<span class="cstat-no" title="statement not covered" >    this.setState({ datasourceName: event.target.value });</span>
<span class="cstat-no" title="statement not covered" >    this.validate();</span>
  }
  changeCheckbox(attr, columnName, event) {
    l</span>et columns = <span class="cstat-no" title="statement not covered" >this.mergedColumns();
    c</span>onst column = <span class="cstat-no" title="statement not covered" >Object.assign({}, columns[columnName], { [attr]: event.target.checked });
<span class="cstat-no" title="statement not covered" >    columns = Object.assign({}, columns, { [columnName]: column });</span>
<span class="cstat-no" title="statement not covered" >    this.setState({ columns }, this.validate);</span>
  }
  changeAggFunction(columnName, option) {
    l</span>et columns = <span class="cstat-no" title="statement not covered" >this.mergedColumns();
    c</span>onst val = (<span class="cstat-no" title="statement not covered" >option) ? option.value : null;
    c</span>onst column = <span class="cstat-no" title="statement not covered" >Object.assign({}, columns[columnName], { agg: val });
<span class="cstat-no" title="statement not covered" >    columns = Object.assign({}, columns, { [columnName]: column });</span>
<span class="cstat-no" title="statement not covered" >    this.setState({ columns }, this.validate);</span>
  }
  render() {
    if (!(this.props.query) || !(this.props.query.results) || !(this.props.query.results.columns)) {
      return (
        &lt;div className="VisualizeModal"&gt;
          &lt;Modal show={this.props.show} onHide={this.props.onHide}&gt;
            &lt;Modal.Body&gt;
              No results available for this query
            &lt;/Modal.Body&gt;
          &lt;/Modal&gt;
        &lt;/div&gt;
      );
    }
    const tableData = this.props.query.results.columns.map((col) =&gt; ({
      column: col.name,
      is_dimension: (
        &lt;input
          type="checkbox"
          onChange={this.changeCheckbox.bind(this, 'is_dim', col.name)}
          checked={(</span>this.state.columns[col.name]) ? <span class="branch-0 cbranch-no" title="branch not covered" >this.state.columns[col.name].is_dim : false}
          className="form-control"
        /&gt;
      ),
      is_date: (
        &lt;input
          type="checkbox"
          className="form-control"
          onChange={this.changeCheckbox.bind(this, 'is_date', col.name)}
          checked={(</span>this.state.columns[col.name]) ? <span class="branch-0 cbranch-no" title="branch not covered" >this.state.columns[col.name].is_date : false}
        /&gt;
      ),
      agg_func: (
        &lt;Select
          options={[
            { value: 'sum', label: 'SUM(x)' },
            { value: 'min', label: 'MIN(x)' },
            { value: 'max', label: 'MAX(x)' },
            { value: 'avg', label: 'AVG(x)' },
            { value: 'count_distinct', label: 'COUNT(DISTINCT x)' },
          ]}
          onChange={this.changeAggFunction.bind(this, col.name)}
          value={(</span>this.state.columns[col.name]) ? <span class="branch-0 cbranch-no" title="branch not covered" >this.state.columns[col.name].agg : null}
        /&gt;
      ),
    }));
    const alerts = this.state.hints.map(<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >(</span>hint, i) =&gt; (</span>
      &lt;Alert bsStyle="warning" key={i}&gt;{hint}&lt;/Alert&gt;
    ));
    const modal = (
      &lt;div className="VisualizeModal"&gt;
        &lt;Modal show={this.props.show} onHide={this.props.onHide}&gt;
          &lt;Modal.Header closeButton&gt;
            &lt;Modal.Title&gt;Visualize&lt;/Modal.Title&gt;
          &lt;/Modal.Header&gt;
          &lt;Modal.Body&gt;
            {alerts}
            &lt;div className="row"&gt;
              &lt;Col md={6}&gt;
                Chart Type
                &lt;Select
                  name="select-chart-type"
                  placeholder="[Chart Type]"
                  options={CHART_TYPES}
                  value={(this.state.chartType) ? this.state.chartType.value : <span class="branch-1 cbranch-no" title="branch not covered" >null}</span>
                  autosize={false}
                  onChange={this.changeChartType.bind(this)}
                /&gt;
              &lt;/Col&gt;
              &lt;Col md={6}&gt;
                Datasource Name
                &lt;input
                  type="text"
                  className="form-control input-sm"
                  placeholder="datasource name"
                  onChange={this.changeDatasourceName.bind(this)}
                  value={this.state.datasourceName}
                /&gt;
              &lt;/Col&gt;
            &lt;/div&gt;
            &lt;hr /&gt;
            &lt;Table
              className="table table-condensed"
              columns={['column', 'is_dimension', 'is_date', 'agg_func']}
              data={tableData}
            /&gt;
            &lt;Button
              onClick={this.visualize.bind(this)}
              bsStyle="primary"
              disabled={(this.state.hints.length &gt; 0)}
            &gt;
              Visualize
            &lt;/Button&gt;
          &lt;/Modal.Body&gt;
        &lt;/Modal&gt;
      &lt;/div&gt;
    );
    return modal;
  }
}
VisualizeModal.propTypes = propTypes;
VisualizeModal.defaultProps = defaultProps;
&nbsp;
export default VisualizeModal;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Apr 11 2017 20:15:55 GMT-0700 (PDT)
</div>
</div>
<script src="../../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../../sorter.js"></script>
</body>
</html>
